package com.joseph.websocket.nio;


import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.*;
import java.util.Iterator;
import java.util.Set;

public class NioClient {


    public static void main(String[] args) throws IOException, InterruptedException {
        //打开一个serverchannel
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress("127.0.0.1", 8088));
        while (true) {
            Thread.sleep(1000);
            ByteBuffer buffer = ByteBuffer.allocate(256);
            buffer.put("abc".getBytes());
            socketChannel.write(buffer);


            buffer.flip();
            socketChannel.read(buffer);
            System.out.println("rev:" + new String(buffer.array()).trim());
        }

    }
}
